#include "User.h"

User::User(std::string username, std::string password, std::string department)
{
    this->_username = username;
    this->_password = password;
    this->_department = department;
}

std::string User::getUsername() const
{
    return _username;
}

std::string User::getDepartment() const
{
    return _department;
}

int User::bookMeetingRoom(int mid)
{
    return DataCenter::getInstance().bookMeetingRoom(*this, mid);
}

int User::cancelMeetingRoom(int mid) const
{
    return DataCenter::getInstance().cancelMeetingRoom(*this, mid);
}

void User::listAllBookedMeetingRooms() const
{
    std::cout << std::setw(8) << "Id"
              << "\t" << std::setw(8) << "Capacity"
              << "\t" << std::setw(8) << "User"
              << "\t" << std::setw(8) << "Department" << std::endl;
    std::cout << std::string(60, '-') << std::endl;
    std::vector<MeetingRoom> rooms = DataCenter::getInstance().bookedMeetingRooms(*this);
    if (rooms.size() != 0)
    {
        for (MeetingRoom &room : rooms)
        {
            std::cout << std::setw(8) << room.getId()
                      << "\t" << std::setw(8) << room.getCapacity()
                      << "\t" << std::setw(8) << room.getUser()->getUsername()
                      << "\t" << std::setw(8) << room.getUser()->getDepartment();

            std::cout << std::endl;
        }
    }
    else
    {
        std::cout << "您还没有预定任意一间会议室" << std::endl;
        std::cout << std::string(60, '-') << std::endl;
    }
}

User User::ERROR_USER = User();